﻿using Longbow.Tasks;
using System;
using System.Threading;
using System.Threading.Tasks;

namespace BlazorAdmin.Models.Dto
{
    public class WorkJob : ITask
    {
        private Action Job;

        public WorkJob(Action job)
        {
            Job = job;
        }

        public Task Execute(IServiceProvider provider, CancellationToken cancellationToken)
        {
            try
            {
                Job?.Invoke();
            }
            catch (Exception ex)
            {
                return Task.FromException(ex);
            }

            return Task.CompletedTask;
        }
    }
}
